﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;

namespace PuzzleDiamonds
{
    public enum ScreenTypes
    {
        ctMain,
        ctGame,
        ctHiscore,
        ctCredits
    }

    [Scriptable]
    public partial class Page : Canvas
    {
        private double m_gameTick;

        public void Page_Loaded(object o, EventArgs e)
        {
            // Required to initialize variables
            InitializeComponent();

            m_gameTick = 0;

            // init sound manager...
            SoundManager.Instance().AddMediaElement(backgroundMusic);
            SoundManager.Instance().AddMediaElement(clickSound);
            SoundManager.Instance().AddMediaElement(victorySound);
            SoundManager.Instance().AddMediaElement(gameoverSound);

            // init screen manager...
            ScreenManager.Instance().AddScreen(new ScreenMain((int)ScreenTypes.ctMain, mainCanvas));
            ScreenManager.Instance().AddScreen(new ScreenGame((int)ScreenTypes.ctGame, gameCanvas));            

            WebApplication.Current.RegisterScriptableObject("PuzzleDiamondsApp", this);
        }

        [Scriptable]
        public void OnGameLoop()
        {
            if ( ScreenManager.Instance().ActiveScreen == null)
                ScreenManager.Instance().ActivateScreen((int)ScreenTypes.ctMain);

            ScreenManager.Instance().Update(m_gameTick++);
        }

        [Scriptable]
        public event EventHandler CallbackToBrowser;

        public void OnNavigateToBlog(object o, MouseEventArgs e)
        {
            if (CallbackToBrowser != null)
                CallbackToBrowser(this, new EventArgs());
        }
    }
}
